#include<iostream>
using namespace std;
typedef unsigned long long LL;
const int N = 1e6 + 10;

int top;
LL st[N];
int main()
{
    int t; cin >> t;
    while(t--)
    {
        top = 0;
        int n; cin >> n;
        while(n--)
        {
            string op; cin >> op;
            if(op == "push")
            {
                LL x; cin >> x;
                st[++top] = x;
            }
            else if(op == "pop")
            {
                if(top == 0) cout << "Empty" << endl;
                else top--;
            }
            else if(op == "query")
            {
                if(top == 0) cout << "Anguei!" << endl;
                else cout << st[top] << endl;
            }
            else
            {
                cout << top << endl;
            }
        }
    }
}